/* function fun (...arg1) {
    // const result = arg1.reduce((prev, item) => prev + item, 0)
    // const fun2 = function (...arg2) {
    //     console.log('arg2', arg2.length, arg2);
    //     if (arg2.length) return fun(...arg1, ...arg2)
    //     else return result
    // }
    // return fun2
    if (arg1.length === 3) return arg1.reduce((prev, item) => prev + item, 0)
    return (...arg2) => fun(...arg1, ...arg2)
}

const result = fun(1, 2, 3) // 6
const result2 = fun(1, 2)(3) // 6
const result3 = fun(1)(2)(3) //6
console.log(result, result2, result3); */
// console.log(result);

function add(...args) {
    const sum = args.reduce((acc, curr) => acc + curr, 0);
  
    return function(...additionalArgs) {
      const combinedArgs = [...args, ...additionalArgs];
      const newSum = combinedArgs.reduce((acc, curr) => acc + curr, 0);
  
      return newSum;
    };
  }
  
  // 测试用例
  console.log(add(1)); // 输出: 1
  console.log(add(1)(2)); // 输出: 3
  console.log(add(1)(2)(3)); // 输出: 6
  console.log(add(1, 2)(3)); // 输出: 6